<template>
  <div class="container-fluid">
    <validator name='v'>
      <form novalidate class="form-horizontal">
        <caption><h1 align="center">功能信息</h1></caption>
        <div class="form-group">
          <label for="f_username" class="col-sm-1 control-label col-sm-offset-1 ">上一级：</label>
          <div class="col-sm-2">
            <div class="form-group">
              <input type="text"  v-model="parent.name" class="form-control" id="f_username" placeholder="上一级" disabled>
            </div>
          </div>
          <label for="f_userid" class="col-sm-1 control-label">功能名称：</label>
          <div class="col-sm-5">
            <div class="form-group">
              <input type="text" v-model="model.name" class="form-control full-with" id="f_userid" placeholder="编号">
            </div>
          </div>
        </div>
        <div class="form-group">
          <label for="f_username" class="col-sm-1 control-label col-sm-offset-1">功能连接：</label>
          <div class="col-sm-8">
            <div class="form-group">
              <input type="text"  v-model="model.link" class="form-control full-with" placeholder="功能连接">
            </div>
          </div>
        </div>
        <div class="form-group">
          <label for="f_username" class="col-sm-1 control-label col-sm-offset-1">页面连接：</label>
          <div class="col-sm-8">
            <div class="form-group">
              <input type="text"  v-model="model.navigate" class="form-control full-with" placeholder="页面连接">
            </div>
          </div>
        </div>

        <div class="form-group">
          <label for="f_username" class="col-sm-1 control-label col-sm-offset-1 ">显示方式：</label>
          <div class="col-sm-2">
            <div class="form-group">
              <v-select :value.sync="model.showmodel" v-model='model.showmodel'
                  :options='showmodels' placeholder='请选择' close-on-select :clear-button='true'></v-select>
            </div>
          </div>

          <label for="f_userid" class="col-sm-1 control-label">图标：</label>
          <div class="col-sm-5">
            <div class="form-group">
              <input type="text" v-model="model.icon" class="form-control full-with" id="f_userid" placeholder="图标路径">
            </div>
          </div>
        </div>

        <div class="form-group">
          <label for="f_username" class="col-sm-1 control-label col-sm-offset-1">描述：</label>
          <div class="col-sm-8">
            <div class="form-group">
              <textarea class="form-control full-with" rows="3" v-model="model.f_description"></textarea>
            </div>
          </div>
        </div>
      </form>
      <!-- <button v-if='$v.valid' @click="confirm()" class="btn btn-success col-sm-1 col-sm-offset-2">保&nbsp;&nbsp;&nbsp;存</button> -->
      <button @click="confirm()" class="btn btn-success col-sm-1 col-sm-offset-2">
        <span class="glyphicon glyphicon-floppy-disk"></span>保存
      </button>
      <button @click='$back()' class="btn btn-default col-sm-1 col-sm-offset-1">
        <span class=" glyphicon glyphicon-log-out"></span>返回
      </button>
    </validator>
  </div>
</template>

<script>
import co from 'co'

let saveGen = function * (self) {
  self.model.showmodel = self.model.showmodel[0]
  //let msg = yield self.$post('rs/data/save', {data:self.model},{resolveMsg:null, rejectMsg:null})
  let msg = yield self.$http.post('rs/data/save', {data:self.model},{resolveMsg:null, rejectMsg:null})
  console.log(msg)
  //yield self.$showMessage(msg.data)
  yield self.$showMessage(msg.bodyText)
  self.$back('refresh')
}

export default {
  title: '修改功能',
  props: ['parent', 'data'],
  data () {
    return {
      model: {
        id: '',
        f_parentname: '',
        name: '',
        link: '',
        navigate: '',
        showmodel: '',
        icon: '',
        f_description: '',
        parentid: '',
        resourcetype: 'function'
      },
      showmodels: [
        {label: '右边', value: '右边'},
        {label: '弹出', value: '弹出'}
      ]
    }
  },
  ready() {
    this.model.f_parentname = this.parent.name
    this.model.parentid = this.parent.id
    this.model = Object.assign({}, this.model, this.data)
    this.model.showmodel = this.model.showmodel.length === 0 ? ['右边'] : [this.model.showmodel]
  },
  methods: {
    confirm () {
      let gen = saveGen(this)
      return co(gen)
    }
  }
}

</script>

<style media="screen">
  .full-with {
    width: 100%;
  }
</style>
